package es.generator.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import es.dto.BaseDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    //插入填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.getValue("createDatetime") == null){
            this.setFieldValByName("createDatetime",new Date(),metaObject);
        }
        this.setFieldValByName("isDeleted", BaseDto.UNDELETE,metaObject);

    }

    //更新填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateDatetime",new Date(),metaObject);
    }
}
